function fig = fm_make()
% FM_MAKE create GUI for UDM definition
%
% HDL = FM_MAKE()
%
%see also FM_BUILD
%
%Author:    Federico Milano
%Date:      11-Nov-2002
%Version:   1.0.0
%
%E-mail:    federico.milano@ucd.ie
%Web-site:  faraday1.ucd.ie/psat.html
%
% Copyright (C) 2002-2019 Federico Milano

global Theme Fig Path

if ishandle(Fig.make), figure(Fig.make), return, end
%screensize = get(0,'ScreenSize');

h0 = figure('Color',Theme.color01, ...
	    'Units', 'normalized', ...
	    'Colormap',[], ...
	    'CreateFcn','Fig.make = gcf;', ...
	    'DeleteFcn','Fig.make = -1;', ...
	    'FileName','fm_make', ...
	    'MenuBar','none', ...
	    'Name','Component Editor', ...
	    'NumberTitle','off', ...
	    'PaperPosition',[18 180 576 432], ...
	    'PaperType','A4', ...
	    'PaperUnits','points', ...
	    'Position',sizefig(0.6992,0.7168), ...
	    'Resize','on', ...
	    'ToolBar','none');

% Static texts for variables
% ----------------------------------------------------------------------------------
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.0235  0.8100  0.1363  0.0286], ...
               'String','Buses','Style','text','Tag','StaticTextBuses');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.1863  0.8100  0.1363  0.0286], ...
               'String','State Variables','Style','text','Tag', ...
               'StaticTextStateVariable');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.3492  0.8100  0.1363  0.0286], ...
               'String','Algebraic Variables','Style','text', ...
               'Tag','StaticTextAlgebraicVariable');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.5120  0.8100  0.1363  0.0286], ...
               'String','Service Variables','Style','text','Tag', ...
               'StaticTextServiceVariable');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.6749  0.8100  0.1363  0.0286], ...
               'String','Parameters','Style','text','Tag', ...
               'StaticTextParameter');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.8369  0.8100  0.1363  0.0286], ...
               'String','Initial Variables','Style','text','Tag', ...
               'StaticTextInitVariable');

% Static texts for equations
% ----------------------------------------------------------------------------------
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.023464     0.4765     0.15642 ...
                    0.027248], 'String','Differential Equations', ...
               'Style','text','Tag','StaticTextDifferentialEquation');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.023464      0.3165     0.15754 ...
                    0.027248], 'String','Algebraic Equations', ...
               'Style','text','Tag','StaticTextAlgebraicEquation');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.023464     0.1553     0.16313 ...
                    0.027248], 'String','Service Equations', ...
               'Style','text','Tag','StaticTextDialogEquation');

% Static texts for input strings
% ----------------------------------------------------------------------------------
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.0235 0.8887 0.2000 0.0286], 'String',['Input ' ...
                    'Variable'],'Style','text','Tag','StaticTextInputVar');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color01, 'HorizontalAlignment','left', ...
               'Position',[0.0235 0.5475 0.2  0.0286], 'String',['Input ' ...
                    'Equation'],'Style','text','Tag','StaticTextInputEq');

ico0 = fm_mat('make_save');
ico1 = fm_mat('make_add');
ico2 = fm_mat('make_delete');
ico3 = fm_mat('make_recall');
ico4 = fm_mat('make_set');
ico5 = fm_mat('make_make');
ico6 = fm_mat('make_open');
ico7 = fm_mat('make_exit');
ico8 = fm_mat('make_settings');
ico9 = fm_mat('make_new');

% General purpose push buttons
% ----------------------------------------------------------------------------------
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02,'Callback','fm_new', 'CData', ...
               ico9,'Position',[0.2035 0.940 0.0346 0.0450], ...
               'TooltipString','New','Tag','PushbuttonNew');
h1 = uicontrol('Parent',h0,'Units','normalized','BackgroundColor', ...
               Theme.color02,'Callback','fm_open', 'CData', ...
               ico6,'Position',[0.2381 0.940 0.0346 0.0450], ...
               'TooltipString','Open','Tag','PushbuttonOpen');
h1 = uicontrol('Parent',h0,'Units','normalized','BackgroundColor', ...
               Theme.color02,'Callback','fm_save(Comp)', 'CData', ...
               ico0,'Position',[0.2727 0.940 0.0346 0.0450], ...
               'TooltipString','Save','Tag','PushbuttonSave');
h1 = uicontrol('Parent',h0,'Units','normalized','BackgroundColor', ...
               Theme.color02,'Callback','fm_build', 'CData', ...
               ico5,'Position',[0.3246 0.940 0.0346 0.0450], ...
               'TooltipString','Build','Tag','PushbuttonBuild');
h1 = uicontrol('Parent',h0,'Units','normalized','BackgroundColor', ...
               Theme.color02,'Callback','fm_comp cprop', 'CData', ...
               ico8,'Position',[0.3592 0.940 0.0346 0.0450], ...
               'TooltipString','Settings','Tag','PushbuttonSett');
h1 = uicontrol('Parent',h0,'Units','normalized','BackgroundColor', ...
               Theme.color02,'Callback','close(gcf);', 'CData', ...
               ico7,'Position',[0.4111 0.940 0.0346 0.0450], ...
               'TooltipString','Close','Tag','PushbuttonClose');

% Push buttons for manipulating equations
% ----------------------------------------------------------------------------------

% recall
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico3,'Callback',['fm_comp ' ...
                    'mcallxe'],'Position',[0.9372 0.4333 0.0346 ...
                    0.0450], 'TooltipString','Recall','Tag', ...
               'PushbuttonRecallStateEq');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico3,'Callback',['fm_comp ' ...
                    'mcallae'],'Position',[0.9372 0.2726 0.0346 ...
                    0.0450], 'TooltipString','Recall','Tag', ...
               'PushbuttonRecallAlgEq');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico3,'Callback',['fm_comp ' ...
                    'mcallse'],'Position',[0.9372 0.1118 0.0346 ...
                    0.0450], 'TooltipString','Recall','Tag', ...
               'PushbuttonRecallServiceEq');

% add
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico1,'Callback',['fm_comp ' ...
                    'maddxe'],'Position',[0.9372 0.3883 0.0346 ...
                    0.0450], 'TooltipString','Add','Tag', ...
               'PushbuttonAddStateEq');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico1,'Callback',['fm_comp ' ...
                    'maddae'],'Position',[0.9372 0.2276 0.0346 ...
                    0.0450], 'TooltipString','Add','Tag','PushbuttonAddAlgEq');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico1,'Callback',['fm_comp ' ...
                    'maddse'],'Position',[0.9372 0.0668 0.0346 ...
                    0.0450], 'TooltipString','Add','Tag','PushbuttonAddSerEq');

% delete
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico2,'Callback',['fm_comp ' ...
                    'mdelxe'],'Position',[0.9372 0.3433 0.0346 ...
                    0.0450], 'TooltipString','Delete','Tag', ...
               'PushbuttonDelStateEq');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico2,'Callback',['fm_comp ' ...
                    'mdelae'],'Position',[0.9372 0.1826 0.0346 ...
                    0.0450], 'TooltipString','Delete','Tag', ...
               'PushbuttonDelAlgEq');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico2,'Callback',['fm_comp ' ...
                    'mdelse'],'Position',[0.9372 0.0218 0.0346 ...
                    0.0450], 'TooltipString','Delete','Tag', ...
               'PushbuttonDelSerEq');

% Push buttons for manipulating variables
% ----------------------------------------------------------------------------------

% settings
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico4,'Callback',['fm_comp ' ...
                    'xopen'],'Position',[0.1863 0.7550 0.0346 0.0450], ...
               'TooltipString','Settings','Tag','PushbuttonSettStateVar');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico4,'Callback',['fm_comp ' ...
                    'sopen'],'Position',[0.5120 0.7550 0.0346 0.0450], ...
               'TooltipString','Settings','Tag','PushbuttonSettServiceVar');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color02, 'CData', ico4,'Callback',['fm_comp ' ...
                    'popen'],'Position',[0.6749 0.7550 0.0346 0.0450], ...
               'TooltipString','Settings','Tag','PushbuttonSettParameter');

% add
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico1,'Callback','[Buses.name, Buses.n] = fm_add(Buses.name, Buses.n,''ListboxBuses'',''EditTextVariable'');', ...
	'Position',[0.0906 0.7550 0.0346 0.0450],'TooltipString','Add','Tag','PushbuttonAddBus');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico1,'Callback','[State.name, State.n] = fm_add(State.name, State.n,''ListboxState'',''EditTextVariable'');', ...
	'Position',[0.2534 0.7550 0.0346 0.0450],'TooltipString','Add','Tag','PushbuttonAddState');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico1,'Callback','[Servc.name, Servc.n] = fm_add(Servc.name, Servc.n,''ListboxServiceVar'',''EditTextVariable'');', ...
	'Position',[0.5791 0.7550 0.0346 0.0450],'TooltipString','Add','Tag','PushbuttonAddServiceVar');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico1,'Callback','[Param.name, Param.n] = fm_add(Param.name,Param.n,''ListboxParameter'',''EditTextVariable'');', ...
	'Position',[0.7420 0.7550 0.0346 0.0450],'TooltipString','Add','Tag','PushbuttonAddParameter');

% delete
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico2,'Callback','[Buses.name, Buses.n] = fm_del(Buses.name, Buses.n,''ListboxBuses'');', ...
	'Position',[0.1252 0.7550 0.0346 0.0450],'TooltipString','Delete','Tag','PushbuttonDelBus');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico2,'Callback','[State.name, State.n] = fm_del(State.name, State.n,''ListboxState'');', ...
	'Position',[0.2880 0.7550 0.0346 0.0450],'TooltipString','Delete','Tag','PushbuttonDelState');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico2,'Callback','[Algeb.name, Algeb.n] = fm_del(Algeb.name, Algeb.n,''ListboxAlgebraic'');', ...
	'Position',[0.4509 0.7550 0.0346 0.0450],'TooltipString','Delete','Tag','PushbuttonDelAlgebVar');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico2,'Callback','[Servc.name, Servc.n] = fm_del(Servc.name, Servc.n,''ListboxServiceVar'');', ...
	'Position',[0.6137 0.7550 0.0346 0.0450],'TooltipString','Delete','Tag','PushbuttonDelServiceVar');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico2,'Callback','[Param.name, Param.n] = fm_del(Param.name,Param.n,''ListboxParameter'');', ...
	'Position',[0.7766 0.7550 0.0346 0.0450],'TooltipString','Delete','Tag','PushbuttonDelParameter');
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor',Theme.color02, ...
	'CData', ico2,'Callback','[Initl.name, Initl.n] = fm_del(Initl.name, Initl.n,''ListboxInitial'');', ...
	'Position',[0.9386 0.7550 0.0346 0.0450],'TooltipString','Delete','Tag','PushbuttonDelInitVar');

% Component properties
% ----------------------------------------------------------------------------------
h1 = uicontrol('Parent',h0,'Units', 'normalized','BackgroundColor', ...
               Theme.color04, 'ForegroundColor',Theme.color03, ...
               'Position',[0.0235 0.940 0.1600 0.0450], 'Style', ...
               'frame','Tag','Frame1');
h(1) = uicontrol('Parent',h0,'Callback','fm_comp name','Units', ...
                 'normalized','BackgroundColor',Theme.color04, ...
                 'ForegroundColor',Theme.color07,'FontWeight','bold', ...
                 'Position',[0.0335  0.9472  0.1400  0.0300], ...
                 'Style','text','Tag','EditTextName');

% Edit strings (variables and equations)
% ----------------------------------------------------------------------------------
h(2) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color04, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color05, ...
                 'HorizontalAlignment','left', 'Position',[0.0235 ...
                    0.8524 0.9486 0.0382], 'String','','Style', ...
                 'edit','Tag','EditTextVariable');
h(3) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color04, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color05, ...
                 'HorizontalAlignment','left', 'Position',[0.0235 ...
                    0.5095 0.9486 0.0382], 'String','','Style', ...
                 'edit','Tag','EditTextEquation');

% Variable listboxes
% ----------------------------------------------------------------------------------
h(4) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color03, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color06, ...
                 'HorizontalAlignment','left', 'Position',[0.0235 ...
                    0.5981 0.1363 0.1569],'String','','Style', ...
                 'listbox','Tag','ListboxBuses','Value',1);
h(5) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color03, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color10, ...
                 'HorizontalAlignment','left', 'Position',[0.1863 ...
                    0.5981 0.1363 0.1569],'Style','listbox', ...
                 'String','','Tag','ListboxState','Value',1);
h(6) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color03, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color10, ...
                 'HorizontalAlignment','left', 'Position',[0.3492 ...
                    0.6335 0.1363 0.1215],'String','','Style', ...
                 'listbox','Tag','ListboxAlgebraic','Value',1);
h(7) = uicontrol('Parent',h0,'Units', 'normalized','Callback',['fm_comp ' ...
                    'serv'],'BackgroundColor',Theme.color03, ...
                 'FontName',Theme.font01,'ForegroundColor', ...
                 Theme.color10,'HorizontalAlignment','left', ...
                 'Position',[0.5120 0.6335 0.1363 0.1215], ...
                 'String',' ','Style','listbox','Tag', ...
                 'ListboxServiceVar','Value',1);
h(8) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color03, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color10, ...
                 'HorizontalAlignment','left', 'Position',[0.6749 ...
                    0.5981 0.1363 0.1569],'String','','Style', ...
                 'listbox','Tag','ListboxParameter','Value',1);
h(9) = uicontrol('Parent',h0,'Units', 'normalized', ...
                 'BackgroundColor',Theme.color03, 'FontName', ...
                 Theme.font01,'ForegroundColor',Theme.color10, ...
                 'HorizontalAlignment','left', 'Position',[0.8369 ...
                    0.6335 0.1363 0.1215],'String','','Style', ...
                 'listbox','Tag','ListboxInitial','Value',1);

% Equation listboxes
% ----------------------------------------------------------------------------------
h(10) = uicontrol('Parent',h0,'Units', 'normalized', ...
                  'BackgroundColor',Theme.color03, 'Callback',['fm_comp ' ...
                    'mlistxe'],'FontName',Theme.font01, ...
                  'ForegroundColor',Theme.color10, ...
                  'HorizontalAlignment','left','Position',[0.0235 ...
                    0.3433 0.9137 0.1350], 'String','','Style', ...
                  'listbox','Tag','ListboxStateEquation','Value',1);
h(11) = uicontrol('Parent',h0,'Units', 'normalized', ...
                  'BackgroundColor',Theme.color03, 'Callback',['fm_comp ' ...
                    'mlistae'],'FontName',Theme.font01, ...
                  'ForegroundColor',Theme.color10, ...
                  'HorizontalAlignment','left','Position',[0.0235 ...
                    0.1827 0.9137 0.1350], 'String','','Style', ...
                  'listbox','Tag','ListboxAlgebraicEquation','Value',1);
h(12) = uicontrol('Parent',h0,'Units', 'normalized', ...
                  'BackgroundColor',Theme.color03, 'Callback',['fm_comp ' ...
                    'mlistse'],'FontName',Theme.font01, ...
                  'ForegroundColor',Theme.color10, ...
                  'HorizontalAlignment','left','Position',[0.0235 ...
                    0.0219 0.9137 0.1350], 'String','','Style', ...
                  'listbox','Tag', 'ListboxServiceEquation','Value',1);

% Popup menus for variables
% ----------------------------------------------------------------------------------
h(13) = uicontrol('Parent',h0,'Units', 'normalized', ...
                  'BackgroundColor',Theme.color04,'Callback',['fm_comp ' ...
                    'mmenua'], 'ForegroundColor',Theme.color05, ...
                  'HorizontalAlignment','left','Position',[0.3492 ...
                    0.5981 0.1363 0.0354], 'String',' ','Style', ...
                  'popupmenu','Tag','PopupMenuAlgebraic','Value',1);
h(14) = uicontrol('Parent',h0,'Units', 'normalized', ...
                  'BackgroundColor',Theme.color04,'Callback',['fm_comp ' ...
                    ' mmenus;'], 'ForegroundColor',Theme.color05, ...
                    'HorizontalAlignment','left','Position',[0.5120 ...
                    0.5981 0.1363 0.0354], 'String',' ','Style', ...
                    'popupmenu','Tag','PopupMenuService','Value',1);
h(15) = uicontrol('Parent',h0,'Units', 'normalized', ...
                  'BackgroundColor',Theme.color04,'Callback',['fm_comp ' ...
                    'mmenui'], 'ForegroundColor',Theme.color05, ...
                  'HorizontalAlignment','left','Position',[0.8369 ...
                    0.5981 0.1363 0.0354], 'String',' ','Style', ...
                  'popupmenu','Tag','PopupMenuInit','Value',1);

set(h0,'UserData',h)
if nargout > 0, fig = h0; end
